#pragma once
#ifndef INPUTMANAGER_H_
#define INPUTMANAGER_H_

#include "baseobject.h"
const int SDLK_LAST = 322;
namespace EPOC
{
	class MouseInput
	{
	public:
		enum MOUSE_BUTTON
		{
			kMOUSE_BUTTON_LEFT,
			kMOUSE_BUTTON_MIDDLE,
			kMOUSE_BUTTON_RIGHT
		};
	public:
		MouseInput()
		{
			m_bLeftDown = false;
			m_bMiddleDown = false;
			m_bRightDown = false;

			m_bLeftUp = false;
			m_bMiddleUp = false;
			m_bRightUp = false;

			m_bLeftPressed = false;
			m_bMiddlePressed = false;
			m_bRightPressed = false;

			m_fX = m_fRelX = 0.0f;
			m_fY = m_fRelY = 0.0f;
		}

		inline void Store()
		{
		/*	m_bLeftDownPrev	= m_bLeftDown;
			m_bMiddleDownPrev = m_bMiddleDown;
			m_bRightDownPrev = m_bRightDown;

			m_bLeftUpPrev	= m_bLeftUp;
			m_bMiddleUpPrev = m_bMiddleUp;
			m_bRightUpPrev = m_bRightUp;*/
		}

		inline void Reset()
		{
			if(m_bLeftUp)// && m_bLeftPressed)
			{
				m_bLeftUp = false;
				m_bLeftPressed = false;
			}
			//else if(!m_bLeftUp && m_bLeftPressed)
			//	m_bLeftPressed = false;

			if(m_bMiddleUp)// && m_bMiddlePressed)
			{
				m_bMiddleUp = false;
				m_bMiddlePressed = false;
			}
			//else if(!m_bMiddleUp && m_bMiddlePressed)
			//	m_bMiddlePressed = false;

			if(m_bRightUp)// && m_bRightPressed)
			{
				m_bRightUp = false;
				m_bRightPressed = false;
			}
			//else if(!m_bRightUp && m_bRightPressed)
			//	m_bRightPressed = false;
		}

	public:
		bool m_bLeftDown;
		bool m_bMiddleDown;
		bool m_bRightDown;

		bool m_bLeftUp;
		bool m_bMiddleUp;
		bool m_bRightUp;

		bool m_bLeftPressed;
		bool m_bMiddlePressed;
		bool m_bRightPressed;


		float m_fX;
		float m_fY;
		float m_fRelX;
		float m_fRelY;
	
	}; // class MouseInput
}; //namespace EPOC

namespace EPOC
{

	class KeyboardInput
	{
	public:
		KeyboardInput()
		{	
			memset(&m_rKeyStates[0], 0, sizeof(Uint8)* (SDLK_LAST - 1));
			memset(&m_rPrevKeyStates[0], 0, sizeof(Uint8)* (SDLK_LAST - 1));
		}

		int IsKeyDown(SDL_Keycode nKey) { return m_rKeyStates[nKey];}
		int IsPrevKeyDown(SDL_Keycode nKey) { return m_rPrevKeyStates[nKey];}

	public:
		Uint8 m_rKeyStates[SDLK_LAST];
		Uint8 m_rPrevKeyStates[SDLK_LAST];

	}; // class KeyboardInput
}; // namespace EPOC

namespace EPOC
{
	class TextInput
	{
		TextInput()
		{
			m_cEndCondition = 13;
			m_bListening = false;
			m_sBufferedText.clear();
		};

		void Start(char cEndCondition);
		void Start();
		void End();

		std::string GetLine();

		void HandleEvent(SDL_Event *pEvent);
		inline bool IsListening() { return m_bListening;}

	public:
		bool m_bListening;
		char m_cEndCondition;
		std::string m_sBufferedText;
	
	}; // class TextInput
}; // namespace EPOC


namespace EPOC
{
	class BaseApplication;

	class InputManager : public BaseObject
	{
	public:
		InputManager(BaseApplication *pApplication);
		virtual ~InputManager();
		
		virtual void Cleanup();
		virtual bool Initialize();
		virtual bool Update(float fTimeDelta);

		virtual void HandleEvent(SDL_Event *pEvent);

		inline MouseInput* GetMouseInput() { return m_pMouseInput;}
		inline KeyboardInput* GetKeyboardInput() { return m_pKeyboardInput;}
		inline TextInput* GetTextInput() { return m_pTextInput;}
		

	protected:
		void ProcessMouse(SDL_Event *pEvent);
		void ProcessKeyboard(SDL_Event *pEvent);
		void ProcessTextInput(SDL_Event *pEvent);

	protected:
		MouseInput *m_pMouseInput;
		KeyboardInput *m_pKeyboardInput;
		TextInput *m_pTextInput;

		BaseApplication *m_pApplication;
		
	}; // class InputManager
}; // namespace EPOC

#endif